package com.zzq.controller;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.exceptions.ClientException;
import com.zzq.domain.entity.SmileBlindboxGoods;
import com.zzq.domain.entity.SmilePointGoods;
import com.zzq.domain.search.BlindboxGoodsSearchParamet;
import com.zzq.domain.search.PointGoodsSearchParamet;
import com.zzq.result.SmileResult;
import com.zzq.service.BlindboxGoodsAdminService;
import com.zzq.service.PointGoodsAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RequestMapping("/admin/goods")
@RestController
@Api(value = "商品管理",tags = {"商品管理"})
public class PointGoodsAdminController {

    @Autowired
    PointGoodsAdminService goodsAdminService;

    @Autowired
    BlindboxGoodsAdminService blindboxGoodsAdminService;
    @PostMapping("/list")
    public SmileResult list(@RequestBody PointGoodsSearchParamet searchParamet){
       return goodsAdminService.getPointGoodsDTOList(searchParamet);
    }

    @PostMapping("/add")
    public SmileResult add(@RequestParam(value = "couponRuleId",required = false)Long couponRuleId,
                           @RequestParam(value = "goodsCoverFile",required=false)MultipartFile goodsCoverFile,
                           @RequestParam("pointGoods") String pointGoods) throws IOException, ClientException {
        SmilePointGoods smilePointGoods = JSONObject.parseObject(pointGoods, SmilePointGoods.class);
        return goodsAdminService.add(goodsCoverFile,couponRuleId,smilePointGoods);
    }

    @PostMapping("/upd")
    public SmileResult upd(@RequestParam(value = "goodsCoverFile",required = false)MultipartFile goodsCoverFile,
                           @RequestParam("pointGoods") String pointGoods) throws IOException, ClientException {
        SmilePointGoods smilePointGoods = JSONObject.parseObject(pointGoods, SmilePointGoods.class);
        return goodsAdminService.upd(goodsCoverFile,smilePointGoods);
    }

    @GetMapping("/del")
    public SmileResult del(@RequestParam("goodsId")Long goodsId) {
        return goodsAdminService.del(goodsId);
    }

    @PostMapping("/blindbox/list")
    @ApiOperation("盲盒列表")
    public SmileResult blindboxList(@RequestBody  BlindboxGoodsSearchParamet searchParamet){
       return blindboxGoodsAdminService.list(searchParamet);
    }

    @PostMapping("/blindbox/add")
    @ApiOperation("盲盒添加")
    public SmileResult blindboxAdd(@RequestBody SmileBlindboxGoods blindboxGoods){
        return blindboxGoodsAdminService.add(blindboxGoods);
    }

    @PostMapping("/blindbox/upd")
    @ApiOperation("盲盒更新")
    public SmileResult blindboxUpd(@RequestBody SmileBlindboxGoods blindboxGoods){
        return blindboxGoodsAdminService.upd(blindboxGoods);
    }

    @GetMapping("/blindbox/del")
    @ApiOperation("盲盒删除")
    public SmileResult blindboxDel(@RequestParam("blindboxGoodsId") Long  blindboxGoodsId){
        return blindboxGoodsAdminService.del(blindboxGoodsId);
    }



}
